<template>
  <div id="wrapper" style="padding: 20px">
    <div class="pageHeader">
      <el-page-header @back="goBack" content="编辑">
      </el-page-header>
    </div>
    <el-card class="box-card">
      <el-form label-width="100px">
        <el-form-item label="禅道地址">
          <el-input v-model="zentaoConfig.url"></el-input>
        </el-form-item>
        <el-form-item label="禅道帐号">
          <el-input v-model="zentaoConfig.username"></el-input>
        </el-form-item>
        <el-form-item label="禅道密码">
          <el-input v-model="zentaoConfig.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">修改</el-button>
          <el-button @click="reset">重置</el-button>
          <el-button @click="goBack">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: 'zentaoConfigEdit',
    data() {
      return {
        zentaoConfig: {}
      }
    },
    methods: {
      async getZentaoConfig() {
        let res = await this.$http.get('/api/zentao/getConfig')
        this.zentaoConfig = res.data
      },
      goBack() {
        this.$router.push('/config')
      },
      async submitForm() {
        let res = await this.$http.post('/api/zentao/updateConfig', this.zentaoConfig)
        if(res.code == 0){
          this.$message({
            message: res.message,
            type: 'success'
          })
          this.$router.push('/zentaoConfigDetail')
        }else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      },
      async reset() {
        let res = await this.$http.post('/api/zentao/reset')
        if(res.code == 0){
          this.$message({
            message: res.message,
            type: 'success'
          })
          this.getZentaoConfig()
        }else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      }
    },
    created() {
      this.getZentaoConfig()
    }
  }
</script>

<style>
.pageHeader{
  padding: 10px;
}
</style>
